package tests;

import common.Utils;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;

import java.io.IOException;

public class LoginPage extends Utils {
    public static String url="http://8.137.19.140:9090/blog_login.html";


    public LoginPage()
    {

        super(url);
    }


    /**
     *
     1.检查登录页面是否可以正常打开
     *
     **/
    public  void checkPageRight()
    {
        //检查菜单
        driver.findElement(By.cssSelector("body > div.nav > a:nth-child(4)"));
       driver.findElement(By.cssSelector("body > div.nav > a:nth-child(5)"));
    //检查登录框
        driver.findElement(By.cssSelector("#username"));
        driver.findElement(By.cssSelector("#password"));
        driver.findElement(By.cssSelector("#submit"));

    }

    /**
     2.登录成功---正确的账号和密码
     */

    public void LoginSuc() throws IOException {
        //先清空输入框
        driver.findElement(By.cssSelector("#username")).clear();
        driver.findElement(By.cssSelector("#password")).clear();

        //输入账号密码
        driver.findElement(By.cssSelector("#username")).sendKeys("zhangsan");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#submit")).click();


        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
    //校验登录是否成功-----注销按钮/列表页中的内容都可以
        driver.findElement(By.cssSelector("###"));
    }


    /**
     3.异常登录
     * ----用户名和密码都为空
     * ----用户名为空，密码不为空
     * ----用户名不为空，密码为空
     * ----正确的用户名，错误的密码
     * ----错误的用户名，正确的密码
     * ----用户名和密码都错误
     * ----输入框：输入过长的内容，过短的·，特殊字符·...
     */

    public void  LoginFail() throws IOException {
        //----正确的用户名，错误的密码
        driver.findElement(By.cssSelector("#username")).sendKeys("zhangsan");
        driver.findElement(By.cssSelector("#password")).sendKeys("1111");

        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());

        driver.findElement(By.cssSelector("#submit")).click();

        //等待弹窗出现
        wait.until(ExpectedConditions.alertIsPresent());
    //处理错误弹窗
        Alert alert=driver.switchTo().alert();
        alert.accept();

    }





}
